/**
 * Created by NAT on 2018-02-27.
 */
//浏览器高度
// console.log($('html').height())
// console.log($('.Baby_Healthy_home_right_top_list').offset().top)
var windowOffsetData={
    document:$('html').height(),//html
    mainoffsetTop:$('.Baby_Healthy_home_right_bespeak_list').offset().top,//
    buttongroupHeight:($('.Baby_Healthy_home_right_bespeak_search').outerHeight()|| 0),//按钮组(蓝色按钮)
    searchgroup:Number($('.searchgroup') && $('.searchgroup').height()),//病人库会员中心搜索组
    brand:(Number($('.zcnavbrand').outerHeight())==0?0:Number($('.zcnavbrand').outerHeight()+12)) || 0,
    tableHFheight:140,
    searchgroup2:($('.bespeak_search_container_seive') && $('.bespeak_search_container_seive').outerHeight(true)) || 0,//搜索条件组
    tab:baseFn.notNull2(($('.bespeak_change_list') && $('.bespeak_change_list').outerHeight(true)),true,0),
    oldTableHeight:function(){
        return this.document-this.mainoffsetTop-this.buttongroupHeight-this.searchgroup-this.tableHFheight-this.brand-this.searchgroup2-this.tab
    },
    mainWraperHeight:$('.Baby_Healthy_home_right_bespeak_list').outerHeight(),//右侧card外框高度
    tableElem:41+26+10,//表格头+表格尾+其他
    tableElemMin:41+26,
    cardOffset:12+21,//12是zccard_container或者bespeak_search_container的pdt值+21是表格距离底部的距离
    refresh:function(){
        var _that= this
        _that.document=$('html').height();
        _that.mainWraperHeight=$('.Baby_Healthy_home_right_bespeak_list').outerHeight()
        _that.mainoffsetTop=$('.Baby_Healthy_home_right_bespeak_list').offset().top;
        _that.buttongroupHeight=($('.Baby_Healthy_home_right_bespeak_search').outerHeight()|| 0);//按钮组(蓝色按钮)
        _that.searchgroup=Number($('.searchgroup') && $('.searchgroup').height());//病人库会员中心搜索组
        _that.brand=(Number($('.zcnavbrand').outerHeight())==0?0:Number($('.zcnavbrand').outerHeight()+12)) || 0;
        _that.searchgroup2=baseFn.notNull2(($('.bespeak_search_container_seive') && $('.bespeak_search_container_seive').outerHeight(true)),true,0);
        _that.tab=baseFn.notNull2(($('.bespeak_change_list') && $('.bespeak_change_list').outerHeight(true)),true,0);
    },
    tableHeight:function(type){
        var _offset = this.tableElem+this.cardOffset
        if(type == 1){
            _offset = 90
        }else if(type == 2){
            _offset = 115
        }else if(type == 5){
            _offset += 74
        }else if(type == 'f1'){
            _offset -= this.searchgroup2
        }
        return this.mainWraperHeight-this.buttongroupHeight-this.searchgroup-this.searchgroup2-this.tab-this.brand-_offset
    }
}
var baseFilterFn={
    input:function(data,curDataKey,curDomName,isNull,nullData,calFn){
        //data:原始数据 curDataKey:当前添加的key名字  curDomName:从哪一个dom取dom的名字,isNull:可不可以为空,nullData:为空时填充的data,calFn:操作之后执行的回调函数
        if(baseFn.notNull($(curDomName).val())){
            data[curDataKey] = $(curDomName).val()
        }else if(isNull){
            data[curDataKey] = nullData
        } 
        if(calFn){
            calFn()
        }
    },
    select:function(data,curDataKey,curDomName,isNull,nullData,calFn){
        if(baseFn.notNull($(curDomName).val())){
            data[curDataKey] = $(curDomName).val()
        }else if(isNull){
            data[curDataKey] = nullData
        }
        if(calFn){
            calFn()
        }
    },
    select2:function(data,curDataKey,curDomName,isNull,nullData,calFn){
        if(baseFn.notNull($(curDomName).val())){
            data[curDataKey] = $(curDomName).val()
        }else if(isNull){
            data[curDataKey] = nullData
        }
        if(calFn){
            calFn()
        }
    }
}
//表格列表过滤函数组
var listSearchingFn={
    patient:function(dom,onlyData){//病人库
        
        var keys = $(dom).find('.searchwrap')
        var _upData = {
            subclinicId:$('.subclinicselect').val(),
            fromPage:'0'
        }
        //过滤条件
        keys.each(function(val,elm){
            var _key = $(elm).data('vals');
            if($(elm).attr('rel') == 'on'){
                var _value = $(elm).find('.active').data('vals')
                _upData[_key]=_value
            }
        })
        
        baseFilterFn.input(_upData,'userPhone','.bespeak_search_input');//右上角搜索
        baseFilterFn.input(_upData,'numberStart','.js_paycount_input',true,0);//最小就诊次数
        baseFilterFn.input(_upData,'numberEnd','.js_paycount_input2');//最大就诊次数
        //就诊次数判断
        if(baseFn.notNull($('.js_paycount_input2').val()) && baseFn.notNull($('.js_paycount_input').val()) && (Number(_upData.numberStart) > Number(_upData.numberEnd))){
            $('.js_paycount_input2').val('')
            baseFn.infoDialog('就诊最大次数不能小于最小次数')
            return false;
        };
        if(onlyData){
            return _upData
        }
        //表格渲染
        // patientsDT.settings()[0].ajax.data=_upData
        baseFn.objDelElm(patientsDTdata,'limit')
        for(var i in _upData){
            patientsDTdata[i] = _upData[i]
        }
        
        patientsDT.ajax.reload()
    },
    vip:function(dom,onlyData){//会员中心
        var keys = $(dom).find('.searchwrap')
        var _upData = {
            subclinicId:$('.subclinicselect').val(),
            fromPage:'0'
        }
        //过滤条件
        keys.each(function(val,elm){
            var _key = $(elm).data('vals');
            if($(elm).attr('rel') == 'on'){
                var _value = $(elm).find('.active').data('vals')
                _upData[_key]=_value
            }
        })
        baseFilterFn.input(_upData,'userPhone','.bespeak_search_input');//右上角搜索
        baseFilterFn.input(_upData,'numberStart','.js_paycount_input',true,0);//最小就诊次数
        baseFilterFn.input(_upData,'numberEnd','.js_paycount_input2');//最大就诊次数
        baseFilterFn.input(_upData,'rechargeFrom','.js_recharge_input');//最小充值金额
        baseFilterFn.input(_upData,'rechargeTo','.js_recharge_input2');//最大充值金额
        //就诊次数判断
        if(baseFn.notNull($('.js_paycount_input2').val()) && baseFn.notNull($('.js_paycount_input').val()) && _upData.numberStart > _upData.numberEnd){
            // $('.js_paycount_input').val(0)
            $('.js_paycount_input2').val('')
            baseFn.infoDialog('就诊最大次数不能小于最小次数')
            return false;
        }
        //就诊充值金额
        if(baseFn.notNull($('.js_recharge_input2').val()) && baseFn.notNull($('.js_recharge_input').val()) && _upData.rechargeFrom > _upData.rechargeTo){
            // $('.js_recharge_input').val(0)
            $('.js_recharge_input2').val('')
            baseFn.infoDialog('充值最大金额不能小于最小金额')
            return false;
        }
        if(onlyData){
            return _upData
        }
        //表格渲染
        // userDT.settings()[0].ajax.data=_upData
        baseFn.objDelElm(userDTdata,'limit')
        for(var i in _upData){
            userDTdata[i] = _upData[i]
        }
        
        userDT.ajax.reload()
    }
}
// 表格复选框
$('.zccheckbox').on('click',function(){
    if($(this).hasClass('zccheckbox_checked')){
        $(this).removeClass('zccheckbox_checked')
    }else{
        $(this).addClass('zccheckbox_checked')
    }
})
//搜索条件
$('.searchelm').on('click',function(){
    $(this).addClass('active').siblings('.searchelm').removeClass('active')
})
//编辑列表切换
function zcEditData(type){
    if(type=='edit'){
        $('.zcwrap_list').hide()
        $('.zcwrap_edit').show()
    }else if(type == 'list'){
        $('.zcwrap_list').show()
        $('.zcwrap_edit').hide()
    }  
}
function HtmlTempl(opts){
    var _html=''
    if(opts.type == 'list'){
        _html='<div class="cols20 rows zcformelm">\
        <a href="javascript:void(0)" data-vals="'+res.results[h2].treatmentId+'" class="font_blue caselistelm">'+baseFn.timestampToTime(res.results[h2].treatmentTime)+' '+res.results[h2].userName+' </a>\
        </div>'
    }
    return _html
}


//复选框
$(document).on('click','input[type=checkbox].checkbox',function(){
    if($(this).hasClass('checkBox_checked')){
        $(this).removeClass("checkBox_checked");
    }else{
        $(this).addClass('checkBox_checked')
    }
})
// $.post(baseUrl.base+baseUrl.sysuser +'',{},function(res){
//     if(res.code==0){
        
//     }else{
//         baseFn.infoDialog(res.msg)
//     }
// },'json')
baseFn.powerFn()